<template>
	<view class="form-box">
		<Registration ref='Registration' :list='listFrom' :listData='model' :listRules='rules' />
		<u-button @click="submit">提交</u-button>
	</view>
</template>
<script>
	import Registration from '@/components/form/index.vue'
	export default {
		data() {
			return {
				listFrom: [{
						type: 'input',
						name: 'name',
						label: '姓名',
					},
					{
						type: 'textarea',
						name: 'textarea',
						label: '富文本',
					},
					{
						type: 'select',
						name: 'sex',
						label: '性别',
						show: false,
						arr: [
							[{
									name: '男',
									id: 1
								},
								{
									name: '女',
									id: 2
								},
								{
									name: '保密',
									id: 3
								},
							]
						]
					},

					{
						type: 'radio',
						name: 'fruit',
						label: '水果',
						cid: '4',
						arr: [{
								name: '苹果',
								value: '1',
								disabled: false
							},
							{
								name: '香蕉',
								disabled: false,
								value: '2',
							},
							{
								name: '橙子',
								disabled: false,
								value: '3',
							}, {
								name: '榴莲',
								disabled: false,
								value: '4',
							}
						],
						children: {
							pid: 'name',
							type: 'input',
							name: 'other',
							label: '',
						}


					},
					{
						type: 'checkbox',
						name: 'fruit2',
						label: '水果2',
						cid: '4',
						arr: [{
								name: '苹果',
								value: '1',
								disabled: false
							},
							{
								name: '香蕉',
								disabled: false,
								value: '2',
							},
							{
								name: '橙子',
								disabled: false,
								value: '3',
							}, {
								name: '榴莲',
								disabled: false,
								value: '4',
							}
						],
						children: {
							pid: 'fruit2',
							type: 'input',
							name: 'other2',
							label: '',
						}
					},
					{
						type: 'calendar',
						name: 'calendar',
						label: '时间',
						show: false,
					}
				],
				model: {
					name: '',
					sex: '',
					fruit: '',
					fruit2: '',
					calendar: ''
				},
				rules: {
					'name': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					'sex': {
						type: 'string',
						required: true,
						message: '请选择男或女',
						trigger: ['blur', 'change']
					},
				},


			};
		},
		components: {
			Registration
		},
		methods: {
			submit() {
				this.$refs.Registration.formEl.validate().then(res => {
					console.log(this.$refs.Registration.model);
					uni.$u.toast('校验通过')
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})
			}
		},
		onReady() {
			// setTimeout(() => {
			// 	this.listFrom = []
			// }, 3000)
		}
	};
</script>
<style lang="scss">
	@import './index.scss'
</style>